﻿var loginUserId;
var loginUserName;

var page1 = new Sail.page({
    name     : "mainList",                  //定义页面对象的唯一标识 名称
    mode     : 'list',                      //这只页面对象的运行模式：列表页面
	isIframe : true,
    
    frames   : {
        name     : "listFrame",                 //该frame对象的唯一标识
        title    : "数据列表",             //标题文本

        //-------------------------------------------------------------------------------
        //以JSON形式描述 frame 的构成(包含哪些 item)
        //-------------------------------------------------------------------------------
        items    : [
                {
                name  : "search",   
                type  : "form", 
                title : "查询条件",
                "isSearch" : true,
                "items" : [
                {
                  type:"input", 
                  title:"打款类别编码",   
                  dataIndex:'filter_LIKES_code'
                },{
                  type:"input", 
                  title:"打款类别名称",   
                  dataIndex:'filter_LIKES_name'
                },{
        					type:"input", 
        				title:"录入人",
        					dataIndex : "filter_LIKES_creator.name"
                }
		            ],
                "layoutConfig" : {
                    columns : 4
                },
                "layout" : [
                    {
                	  items:[
			                {'name':'打款类别编码'},
			          	    {'name':'打款类别名称'},
			          	    {'name':'录入人'}
                           ]
                    }
                ]
            },
            {
                name      : "gridMain",
                type      : "grid",
                title     : "打款类别列表",
                tbar      : ['新增','-','删除','-','复制','-'],
                pageSize:12,
            	  singleSelect:false,
            	  height:MAIN_HEIGHT,
                bindRelation   : {
                    root  :"dataset.dictionary",
                    id    : "id",
                    field :[,"creatorId"],
                    col   :[
                    		 {"header":"名称",  "align":"left","width":100,   "dataIndex":"name" },
                    		 {"header":"编号",  "align":"left","width":100,   "dataIndex":"code" }, 
                         {"header":"录入人",   "align":"left","width":60,   "dataIndex":"creatorName" },
                         {"header":"录入时间", "width":90,   "dataIndex":"createTime","renderer":Sail.toFullDate},
                         {"header":"修改",     "width":50,   "actionCol" :true, renderer:
                        	function(value,p,r){
	                   			  var creatorId = r.get('creatorId');
	                   				return "<span class=actionSpan>修改</span>";
            				      }  
                        }
                    ]
                    
                }
            }
        ],        
		layout : [
    		{
            items:[{'name':"search"}]
        },
        {
            items:[{'name':"gridMain"}]
        }
        ],
        
        bindEvent2Items : function(){   
			//主、从grid
			var grid = $('gridMain');
	
			//查询事件
			$('search').addButtonHandler('查询',function(){
				queryData();
		    });

			//重置
			$('search').addButtonHandler('重置',function(){
				setInitValue();
		  });

        //新增
        grid.addButtonHandler('新增',function(){
            Sail.open("materialDKLBDetail.html","add",{},LITTLE_MODWIN_HEIGHT,LITTLE_MODWIN_WIDTH);
            grid.load();
        });
            
          
        //删除
        grid.addButtonHandler('删除',function(){
          var ids = grid.getSelections('id').join(':');
          if (ids==''){
            return;
          }
          if(confirm("确认要删除所选择的空调机型吗？")==false){
            return;
          }
          Sail.postData('../../dictionary.do?method=delete',
          {'ids':ids},
          function(flag,getData){
              if(flag == "true"){
                  Ext.Msg.alert("提示","操作成功!");
                  subgrid.removeAll();
                  grid.load();
              }
              else{
                  Ext.Msg.alert("警告",getData.dataset.response.content);
              }
          });
        });
            
        //修改
        grid.addAction('修改',function(id){
            Sail.open("materialDKLBDetail.html","update",{"id":id},LITTLE_MODWIN_HEIGHT,LITTLE_MODWIN_WIDTH);
            grid.load();
        });
            
        //复制
          grid.addButtonHandler('复制',function(){
          	var ids = grid.getSelections('id');
          	if (ids.length <= 0){
          		Ext.Msg.alert("提示","复制前，请选择一个样本！");
          		return;
          	}
          	
          	if (ids.length != 1){
          		Ext.Msg.alert("提示","复制新增时，您只能指定一个样本！");
          		return;
          	}
          	
             Sail.open("materialDKLBDetail.html","update",{"id":ids[0], "isCopyAdd":"true"},LITTLE_MODWIN_HEIGHT,LITTLE_MODWIN_WIDTH);
             grid.load();
          });
            
          //选择首行,显示子列表数据
          grid.on('afterload',function(){
              grid.selectFirstRow();
          });
          
        }        
    },
    //进入页面自动查询数据
	afterRun : function(){
    	//设初值
    	setInitValue();
    	//查询数据
    	queryData();
	},
	
	afterLoadLoginInfo:function(){
		loginUserId = this.getUser();
		loginUserName = this.getOpername();
	}
});

page1.run();

function setInitValue(){
	if (!$('gridMain').getButton("新增").disabled)
	{	
		//$('录入人').setData(loginUserId, loginUserName);
	}
}

function queryData(){
	var searchInfo = $('search').getSearch();
	var url = "../../dictionary.do?method=list&filter_EQS_type="+DICTIONARY_TYPE_MATERIAL_DKLB+searchInfo;
	$('gridMain').load(url);
}